/*
 * @Author: Mcfly
 * @Date: 2021-10-16 17:31:52
 * @LastEditTime: 2021-10-16 17:38:28
 * @LastEditors: Mcfly
 * @Description: 限幅滤波器
 * @FilePath: \FTTfly\Filter\LimitAmpFilter.c
 * 本人github:https://github.com/McflyWZX
 */
#include <stdlib.h>
#include "LimitAmpFilter.h"

LimitAmpParameter*  LimitAmpFilter_Init(float limitUp, float limitDown)
{
    LimitAmpParameter *filter = malloc(sizeof(LimitAmpParameter));
    filter->limitUp = limitUp;
    filter->limitDown = limitDown;
    return filter;
}

float LimitAmpFilter_Work(float curr_input, float last_out, LimitAmpParameter *filter)
{

	if(curr_input >= last_out)
	{
		float out_max = last_out + filter->limitUp;
		if(curr_input > out_max)
			return out_max;
		return curr_input;
	} else {
		float out_min = last_out - filter->limitDown;
		if(curr_input < out_min)
			return out_min;
		return curr_input;
	}
}
